<?PHP
##################################
/* 溯源日志 */
##################################

class Admin_source_log_Controller extends controller_admin{
	function __construct(){
		parent::__construct();
	 	$this->assign('nav','溯源管理 - 供应录入');
		$this->assign('menuid1','7');
		$this->assign('menuid2','5');
		//权限判断
		factory::module('admin')->authSys('source_log');
	}
	function index__(){
		if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
		{
			#得到传递过来的参数
			$_POST=format::addslash_deep($_POST);
			if(!isset($_POST['start']))			$_POST['start']			= 0;
			if(!isset($_POST['limit']))			$_POST['limit']			= 10;
			if(!isset($_POST['sort']))			 $_POST['sort']			= 'a.id';
			if(!isset($_POST['dir']))				 $_POST['dir']				= 'DESC';
			if(!isset($_POST['keywords']))   $_POST['keywords']  = ''; 
			if(!isset($_POST['b_date']))    $_POST['b_date']  = ''; 
			if(!isset($_POST['e_date']))    $_POST['e_date']  = ''; 
			
  	  #查询条件
			$sql_where = ' where w.deleted=0 '.func::speedsearch($_POST['keywords'],array( 'b.code' 	,'a.dates','a.logs','c.name' ));
			if($_POST['b_date']!=''){
				$sql_where .= ' and a.dates >= "'.$_POST['b_date'].' 00:00:00"';	
			}
			if($_POST['e_date']!=''){
				$sql_where .= ' and a.dates <= "'.$_POST['e_date'].' 23:59:59"';	
			}
			#排序信息
			$sql_order = " ORDER BY ".$_POST['sort'].' '.$_POST['dir']." LIMIT ".$_POST['start'].", ".$_POST['limit'];
			#先查总数 
			$sql = "
			select 
			count(a.id) 
			from t_source_logs a
			left join t_source w on a.source_id=w.id
			left join t_sendpi b on w.sendpi_id=b.id  
			left join t_user c on a.user_id=c.id
			".$sql_where ;  
			$db = factory::getDBO();
			$rows = $db->LoadResult($sql); 
			if($rows){
				#检索出具体数据
				$sql = "select 
					a.*,
					b.id as sendpi_id,
					b.code,
					c.name
				from t_source_logs a
				left join t_source w on a.source_id=w.id
				left join t_sendpi b on w.sendpi_id=b.id  
				left join t_user c on a.user_id=c.id
				".$sql_where.$sql_order;
				$rs = $db->LoadAssocList($sql);
				#输出结果
				echo '({"total":"'.$rows.'","results":'.json_encode($rs).'})';
			}else{
				echo '({"total":"0","results":[]})';
			}
			exit();  
		}
	}
	 
	  


 
}
?>